package com.kkd.kkdapp.adapter;

import java.util.List;

import com.kkd.kkdapp.R;
import com.kkd.kkdapp.http.entity.FinancialPlan;
import com.kkd.kkdapp.utils.LogUtil;
import com.kkd.kkdapp.view.RoundImageView;
import com.nostra13.universalimageloader.core.ImageLoader;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class FinancialPlanConditionAdapter extends BaseAdapter {

	private Context context;
	private List<FinancialPlan> poilist;

	public FinancialPlanConditionAdapter(Context context,
			List<FinancialPlan> poilist) {
		this.context = context;
		this.poilist = poilist;
	}

	@Override
	public int getCount() {
		return poilist.size();
	}

	@Override
	public Object getItem(int position) {
		return poilist.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHodler viewhodler;
		if (convertView == null) {
			convertView = View.inflate(context,
					R.layout.condition_listview_item, null);
			viewhodler = new ViewHodler();
			convertView.setTag(viewhodler);
		} else {
			viewhodler = (ViewHodler) convertView.getTag();
		}
		viewhodler.phone = (TextView) convertView.findViewById(R.id.phone);
		viewhodler.date = (TextView) convertView.findViewById(R.id.date);
		viewhodler.count = (TextView) convertView.findViewById(R.id.count);
		viewhodler.iv_head = (RoundImageView) convertView
				.findViewById(R.id.iv_head);
		viewhodler.phone.setText(poilist.get(position).getInvestorNick());

		viewhodler.count
				.setText((poilist.get(position).getPayAmount() / 100 + poilist
						.get(position).getCouponsAmount() / 100) + "元");
		viewhodler.date.setText(poilist.get(position).getFinanceDateString());
		LogUtil.e("imgurl", poilist.get(position).getImageUrl());
		ImageLoader.getInstance().displayImage(
				poilist.get(position).getImageUrl(), viewhodler.iv_head,
				R.drawable.myrecommendfriend_head);
		return convertView;
	}

	static class ViewHodler {
		TextView phone;
		TextView date;
		TextView count;
		RoundImageView iv_head;
	}
}
